<?php

if($_GET['random'] != '20130826') {
    return ;
}
    // 定义数据库常量
    define( 'DB_USER'   , 'root'        );
    define( 'DB_PASSWD' , 'coolchuan2012'     );
    define( 'DB_HOST'   , 'localhost'   );
    define( 'DB_NAME'   , 'catchappdataall');

    // 定义时间常量
    define( 'DAY_TIME'  , 86400    );

    $db_obj = new mysqli( DB_HOST, DB_USER, DB_PASSWD, DB_NAME);



    function display_table( $db_obj, $market_id ) {
         //数据库表
        $db_table_list = array( 1 => '360',2 => 'wandoujia', 3 => 'jifeng',4 => 'baidu',5 => 'anzhi');
        // 时间列表
        $cur_month = date('Ym');
        for($i=0; $i<3; $i++){
            // $cur_times[$i] =  
            $sql = ' select count(id) as id_num, ranktype from jk_apps_data_mobile_' . $db_table_list[$market_id] . '_' . $cur_month . ' where time="'. date('Y-m-d', time()-$i*DAY_TIME) .'" group by ranktype';

            if(!$dataInfos[$i] = $db_obj->query($sql)){
               $dataInfos[$i] = 0; 
            }
        }
        echo '<div class="market-table" >';
        echo '<h1>'. $db_table_list[$market_id] . ' </h1>';
        foreach($dataInfos as $index => $dataInfo){
            echo '<div class="market-col">';
            echo '<table>';
            echo '<tr>'.date('Y-m-d' , time()-$index*DAY_TIME).'</tr>';
            echo '<tr class="info-title"><th>ID数量</th><th>排名类型</th></ul>';
                while($row = $dataInfo->fetch_assoc()){
                    echo '<tr><td>' . $row['id_num'] . '</td><td>' . $row['ranktype'] . '</td></tr>'; 
                }             
            echo '</table>';
            echo '</div>';
        }
        echo '</div>';
    }
    


    
?>

<html>
<body>
    <style>

        body{
            background-color: white;
        }

        .wrap {
            width: 960px;
            height: 100%;
            margin: 0 auto;
        }

        .market-table {
            background-color: #e5e5e5;
            border-radius: 5px;
            box-shadow: 1px 1px 1px #ccc;
            padding: 5px;
            float: left;
            width: 100%;
        }

        .market-table h1 {
            text-align: center;
        }

        .market-col {
            float: left;
            width: 280px;
            display: inline-block;
            text-align: center;
            margin: 0 20px;
        }

        .market-col table {
            text-align: center;
            border: 2px groove gray;
            width: 100%;
        }

        .market-col table td {
            width: 100px;
        }


    </style>
    <div class="wrap">
        <?php 
            for($i=1; $i<=5; $i++)
               display_table($db_obj, $i); 
        ?>
    </div>
</body>
</html>


